home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d875.lha / Blanker / Source.lha / Source / cxhand.c < prev    next >
C/C++ Source or Header  |  1993-05-23  |  4KB  |  166 lines

  1. /** DoRev Header ** Do not edit! **
  2. *
  3. * Name             :  cxhand.c
  4. * Copyright        :  Free Software
  5. * Creation date    :  12-May-93
  6. * Translator       :  SAS/C 6.2
  7. * Compiler opts.   :  See Makefile
  8. *
  9. * Date       Rev  Author               Comment
  10. * ---------  ---  -------------------  ----------------------------------------
  11. * 12-May-93    0  Michael D. Bayne     Commodities handling for Blanker
  12. *
  13. *** DoRev End **/
  14.  
  15. #include <exec/types.h>
  16. #include <dos/dos.h>
  17. #include <libraries/commodities.h>
  18. #include <devices/inputevent.h>
  19.  
  20. #include <clib/exec_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <clib/commodities_protos.h>
  23. #include <clib/alib_protos.h>
  24.  
  25. #include "defs.h"
  26.  
  27. LONG openMainWindow( void );
  28. VOID CloseBlankerWindow( void );
  29. VOID CxBFunc( CxMsg *CxMessage, CxObj *CxObject );
  30.  
  31. extern    struct    NewBroker nbBroker;
  32. extern    struct    Task  *bTask, *Task;
  33. extern    struct    Screen *bScr;
  34. extern    struct    bPrefObject bPrefs;
  35.     struct    MsgPort *bPort;
  36.     CxObj    *bBroker, *pHotKey, *bHotKey, *objectList;
  37.     ULONG    cxSigFlag, cxBlankFlag, timeCount = 0;
  38.  
  39. void __interrupt __saveds CxBFunc( CxMsg *CxMessage, CxObj *CxObject )
  40. {
  41.     struct InputEvent *Event = ( struct InputEvent * )CxMsgData( CxMessage );
  42.  
  43.     if( Event->ie_Class == IECLASS_TIMER ) {
  44.         if( !bTask ) {
  45.             if( ++timeCount >= bPrefs.bTimeout ) {
  46.                 Signal( Task, cxBlankFlag );
  47.                 timeCount = 0;
  48.             }
  49.         }
  50.     } else {
  51.         if( bTask ) {
  52.             Signal( bTask, SIGBREAKF_CTRL_C );
  53.             bTask = 0L;
  54.         }
  55.         timeCount = 0;
  56.     }
  57. }
  58.  
  59. LONG handleCxMess( void )
  60. {
  61.     ULONG msgid, msgtype;
  62.     CxMsg *msg;
  63.  
  64.     while( msg = ( CxMsg * )GetMsg( bPort )) {
  65.         msgid = CxMsgID( msg );
  66.         msgtype = CxMsgType( msg );
  67.         ReplyMsg(( struct Message * )msg );
  68.  
  69.         switch( msgtype ) {
  70.         case CXM_IEVENT:
  71.             switch( msgid ) {
  72.             case EVT_CX_POPUP:
  73.                 openMainWindow();
  74.                 break;
  75.             case EVT_CX_BLANK:
  76.                 Signal( Task, cxBlankFlag );
  77.                 break;
  78.             }
  79.             break;
  80.         case CXM_COMMAND:
  81.         switch( msgid ) {
  82.             case CXCMD_DISABLE:
  83.                 ActivateCxObj( bBroker, 0l );
  84.                 break;
  85.             case CXCMD_ENABLE:
  86.                 ActivateCxObj( bBroker, 1l );
  87.                 break;
  88.             case CXCMD_KILL:
  89.                 return( QUIT );
  90.                 break;
  91.             case CXCMD_APPEAR:
  92.             case CXCMD_UNIQUE:
  93.                 openMainWindow();
  94.                 break;
  95.             case CXCMD_DISAPPEAR:
  96.                 CloseBlankerWindow();
  97.                 break;
  98.             default:
  99.                 break;
  100.             }
  101.         default:
  102.             break;
  103.         }
  104.     }
  105.     return( OK );
  106. }
  107.  
  108. void ShutdownCX( void )
  109. {
  110.     CxMsg *msg;
  111.  
  112.     if( bPort ) {
  113.         if( bBroker ) DeleteCxObjAll( bBroker );
  114.         bBroker = 0l;
  115.         while( msg = ( CxMsg * )GetMsg( bPort )) ReplyMsg(( struct Message * )msg );
  116.         DeletePort( bPort );
  117.         bPort = 0l;
  118.     }
  119. }
  120.  
  121. LONG UpdateCX( void )
  122. {
  123.     ActivateCxObj( bBroker, 0l );
  124.  
  125.     DeleteCxObj( objectList );
  126.     DeleteCxObj( pHotKey );
  127.     DeleteCxObj( bHotKey );
  128.  
  129.     if( objectList = CxCustom( CxBFunc, 0L )) AttachCxObj( bBroker, objectList );
  130.     if( pHotKey = HotKey( bPrefs.pKey, bPort, EVT_CX_POPUP )) AttachCxObj( bBroker, pHotKey );
  131.     if( bHotKey = HotKey( bPrefs.bKey, bPort, EVT_CX_BLANK )) AttachCxObj( bBroker, bHotKey );
  132.  
  133.     if(!( CxObjError( bBroker ))) ActivateCxObj( bBroker, 1l );
  134.     else {
  135.         ShutdownCX();
  136.         return( QUIT );
  137.     }
  138.     return( OK );
  139. }
  140.  
  141. LONG SetupCX( void )
  142. {
  143.     ShutdownCX();
  144.  
  145.     if( bPort = CreateMsgPort()) {
  146.         nbBroker.nb_Port = bPort;
  147.         cxSigFlag = 1L << bPort->mp_SigBit;
  148.         if( bBroker = CxBroker( &nbBroker, NULL )) {
  149.             objectList = CxCustom( CxBFunc, NULL );
  150.             AttachCxObj( bBroker, objectList );
  151.             if( pHotKey = HotKey( bPrefs.pKey, bPort, EVT_CX_POPUP )) AttachCxObj( bBroker, pHotKey );
  152.             if( bHotKey = HotKey( bPrefs.bKey, bPort, EVT_CX_BLANK )) AttachCxObj( bBroker, bHotKey );
  153.             if(!( CxObjError( bBroker ))) {
  154.                 ActivateCxObj( bBroker, 1l );
  155.                 return( OK );
  156.             } else {
  157.                 DeleteCxObjAll( bBroker );
  158.                 bBroker = 0l;
  159.             }
  160.         }
  161.         DeletePort( bPort );
  162.         bPort = 0l;
  163.     }
  164.     return( QUIT );
  165. }
  166.